// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.statement.SQLCheck;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "OracleCheck.h"
#include "../../../../ast/SQLName.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/instanceof.h"
#include "OracleUsingIndexClause.h"

// @Override
void OracleCheck::accept0(SQLASTVisitor_ptr visitor)
{
  if (instanceof <SQLASTVisitor, OracleASTVisitor>(visitor))
  {
    accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
    return;
  }

  SQLCheck::accept(visitor);
}

void OracleCheck::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleCheck)))
  {
    acceptChild(visitor, this->SQLConstraintImpl::getName());
    acceptChild(visitor, this->getExpr());

    acceptChild(visitor, using_);
    acceptChild(visitor, exceptionsInto);
  }
  visitor->endVisit(SharedObject(OracleCheck));
}

BOOL_ptr OracleCheck::getDeferrable()
{
  return deferrable;
}

void OracleCheck::setDeferrable(BOOL_ptr deferrable)
{
  this->deferrable = deferrable;
}

OracleConstraint_Initially_ptr OracleCheck::getInitially()
{
  return initially;
}

void OracleCheck::setInitially(OracleConstraint_Initially_ptr initially)
{
  this->initially = initially;
}

SQLName_ptr OracleCheck::getExceptionsInto()
{
  return exceptionsInto;
}

void OracleCheck::setExceptionsInto(SQLName_ptr exceptionsInto)
{
  this->exceptionsInto = exceptionsInto;
}

OracleUsingIndexClause_ptr OracleCheck::getUsing()
{
  return using_;
}

void OracleCheck::setUsing(OracleUsingIndexClause_ptr using_)
{
  if (using_ != nullptr)
  {
    using_->setParent(SharedObject(OracleCheck));
  }
  this->using_ = using_;
}

void OracleCheck::cloneTo(OracleCheck_ptr x)
{
  SQLCheck::cloneTo(x);
  if (using_ != nullptr)
  {
    x->setUsing(std::dynamic_pointer_cast<OracleUsingIndexClause>(using_->clone()));
  }
  if (exceptionsInto != nullptr)
  {
    x->setExceptionsInto(std::dynamic_pointer_cast<SQLName>(exceptionsInto->clone()));
  }
  x->initially = initially;
  x->deferrable = deferrable;
}

SQLObject_ptr OracleCheck::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleCheck>(new OracleCheck());
  std::shared_ptr<OracleCheck> x = std::dynamic_pointer_cast<OracleCheck>(clone_tmp);
  // OracleCheck x = new OracleCheck();
  cloneTo(x);
  return x;
}
